#pragma once


#include <QCommonStyle>
#include <QFont>
#include <QtGui>
#include <QRect>
#include <QSize>
#include <QStyle>

#include <array>
using std::array;

#include <functional>
using std::function;


constexpr QStyle::PrimitiveElement QSTYLE_PE_FRAME_END = QStyle::PE_FrameTabBarBase;


namespace GesusTheme { // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	/*  Colors
	 -------------------------------------------------------*/
	const QColor ACCENT_COLOR          = QColor(152, 116, 192);
	const QColor FRAME_COLOR           = QColor( 84,  80,  84);
	const QColor FRAME_HIGHLIGHT_COLOR = QColor(104, 100, 104);
	const QColor HIGHLIGHT_BG_COLOR    = QColor( 63,  59,  63);
	const QColor INNER_BG_COLOR        = QColor( 44,  40,  44);
	const QColor OUTER_BG_COLOR        = QColor( 25,  21,  25);
	const QColor TEXT_COLOR            = QColor(242, 241, 242);
	const QColor TEXT_HIGHLIGHT_COLOR  = QColor(255, 255, 255);

	const QColor BG_COLOR_VARIANTS[2] = { INNER_BG_COLOR,
										  OUTER_BG_COLOR };
	
	const QColor TEXT_COLOR_VARIANTS[2] = { TEXT_COLOR,
	                                        TEXT_HIGHLIGHT_COLOR };

	/*  NOTE: QRgb is changed to QColor to decrease 
	 *        RAM usage by ~4MB (commit e7fc05c)
	 */
	
	/*  Misc
	 -------------------------------------------------------*/
	constexpr int FRAME_THICKNESS = 1;

	const QFont DEFAULT_FONT = QFont("Helvetica");

	/*  Style hints
	 -------------------------------------------------------*/
	constexpr int NO_ANIMATION = 0;
}; // namespace GesusTheme >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


inline QPalette gesusPalette = []() {
	QPalette p;

	p.setColor(QPalette::WindowText,      GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::Button,          GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::Light,           GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::Midlight,        GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::Dark,            GesusTheme::OUTER_BG_COLOR      );
	p.setColor(QPalette::Mid,             GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::Text,            GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::BrightText,      GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::ButtonText,      GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::Base,            GesusTheme::OUTER_BG_COLOR      );
	p.setColor(QPalette::Window,          GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::Shadow,          GesusTheme::OUTER_BG_COLOR      );
	p.setColor(QPalette::Highlight,       GesusTheme::HIGHLIGHT_BG_COLOR  );
	p.setColor(QPalette::HighlightedText, GesusTheme::TEXT_HIGHLIGHT_COLOR);
	p.setColor(QPalette::Link,            GesusTheme::ACCENT_COLOR        );
	p.setColor(QPalette::LinkVisited,     GesusTheme::ACCENT_COLOR        );
	p.setColor(QPalette::AlternateBase,   GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::ToolTipBase,     GesusTheme::INNER_BG_COLOR      );
	p.setColor(QPalette::ToolTipText,     GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::PlaceholderText, GesusTheme::TEXT_COLOR          );
	p.setColor(QPalette::Accent,          GesusTheme::ACCENT_COLOR        );
	
	return p;
}();


class GesusStyle : public QCommonStyle
{
	Q_OBJECT
	
	static constexpr int MENU_BAR_ITEM_MARGIN_H  = 2;
	static constexpr int MENU_BAR_ITEM_MARGIN_V  = 2;
	
	static constexpr int MENU_ITEM_MARGIN_H  = 2;
	static constexpr int MENU_ITEM_MARGIN_V  = 1;
	
	static constexpr int TAB_BAR_TAB_MARGIN_H = 2;
	static constexpr int TAB_BAR_TAB_MARGIN_V = 2;
	
	static constexpr int TEXT_MARGIN_DEFAULT_H = 2;
	static constexpr int TEXT_MARGIN_DEFAULT_V = 2;
	
public: // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
	explicit GesusStyle(void);
	
	void  drawControl(QStyle::ControlElement, const QStyleOption *, QPainter *, const QWidget * = nullptr) const override;
	
	void  drawItemText(QPainter *, const QRect &, int, const QPalette &, bool, const QString &, QPalette::ColorRole) const override;
	
	void  drawPrimitive(QStyle::PrimitiveElement, const QStyleOption *, QPainter *, const QWidget * = nullptr) const override;
	
	QSize sizeFromContents(QStyle::ContentsType, const QStyleOption *, const QSize &, const QWidget * = nullptr) const override;
	
	int   styleHint(QStyle::StyleHint, const QStyleOption * = nullptr, const QWidget * = nullptr, QStyleHintReturn * = nullptr) const override;
	
	QRect subElementRect(QStyle::SubElement, const QStyleOption *, const QWidget * = nullptr) const override;
	
private: // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
};
